/*
 * File: javaScriptServlet.java Author: Robert Bittle <guywithnose@gmail.com>
 */
package servlets;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import data.FileReader;
import data.Memcache;
import fileHandlers.CssMinifier;

/**
 * The Class javaScriptServlet.
 * 
 * @author Dude
 */
public class CssServlet extends FoxtrotBravoServlet
{
  /*
   * (non-Javadoc)
   * 
   * @see
   * javax.servlet.http.HttpServlet#doGet(javax.servlet.http.HttpServletRequest
   * , javax.servlet.http.HttpServletResponse)
   */
  @Override
  protected void doGet(HttpServletRequest req, HttpServletResponse resp)
      throws ServletException, IOException
  {
    resp.setHeader("Content-Type", "text/css");
    String files = req.getParameter("files");
    if (files != null)
    {
      String[] arFiles = files.split(",");
      for (int i = 0; i < arFiles.length; i++)
      {
        String fileName;
        fileName = "css/" + arFiles[i];
        if (BrowserCache.handleCache(req, resp, 3600/*1 hour*/, fileName))
        {
          return;
        }
        String Contents = null;
        if (isDevMode(req))
        {
          Memcache.clear();
          Contents = FileReader.getFileContents(fileName);
        } else
        {
          Contents = CssMinifier.minify(fileName);
        }
        resp.getWriter().println(Contents);
      }
    }
  }

}
